package com.woniuxy.kaer.service.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.kaer.service.entity.Consumables;
import com.woniuxy.kaer.service.entity.ServiceProject;
import com.woniuxy.kaer.service.mapper.ConsumablesMapper;
import com.woniuxy.kaer.service.mapper.ServiceProjectMapper;
import com.woniuxy.kaer.service.param.AddConsumablesParam;
import com.woniuxy.kaer.service.service.ConsumablesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 程诗洋
 * @since 2025年02月17日
 */
@Service
public class ConsumablesServiceImpl extends ServiceImpl<ConsumablesMapper, Consumables> implements ConsumablesService {

    @Resource
    private ServiceProjectMapper serviceProjectMapper;
    @Resource
    private ConsumablesMapper consumablesMapper;
    @Override
    public void AddConsumables(AddConsumablesParam param) throws Exception {
//        ServiceProject serviceProject = serviceProjectMapper.selectById(param.getServiceProjectId());
//        if(null==serviceProject){
//            throw new Exception("没有该服务项目");
//        }
        Consumables consumables = BeanUtil.toBean(param, Consumables.class);
        consumablesMapper.insert(consumables);
    }

    @Override
    public List<Consumables> getConsumablesByServiceProjectId(Integer serviceProjectId) throws Exception {
        QueryWrapper<Consumables> consumablesQueryWrapper = new QueryWrapper<>();
        consumablesQueryWrapper.eq("service_project_id",serviceProjectId);
        List<Consumables> consumablesList = consumablesMapper.selectList(consumablesQueryWrapper);
        return consumablesList;
    }
}
